<template>
	<view class="MerchantForm">
		<u-navbar
			title="创建商户" 
			left-text="" 
			@leftClick="onClickBack"
			:placeholder="true"
			:fixed="true"
			:safeAreaInsetTop="true"
			:border="true"
		></u-navbar>
		<view class="content">
			<view class="w-pb-10">
				<u-steps :current="current" activeColor="#1678ff" inactiveColor="#d9d9d9">
					<u-steps-item title="创建商户" class="text-active">
						<text class="slot-icon slot-icon-active" slot="icon">1</text>
					</u-steps-item>
					<u-steps-item title="完善资料" :class="current >= 1?'text-active':''">
						<text class="slot-icon" :class="current >= 1?'slot-icon-active':''" slot="icon">2</text>
					</u-steps-item>
					<u-steps-item title="设置费率" :class="current >= 2?'text-active':''">
						<text class="slot-icon" :class="current >= 2?'slot-icon-active':''" slot="icon">3</text>
					</u-steps-item>
				</u-steps>
			</view>
			<view v-if="step === 0">
				<view class="newMerchant">
					创建新的商户
				</view>
				<view class="shopType">
					<u--form
						labelPosition="left"
						:model="formData"
						ref="form1" >
						<u-form-item
							label="商户简称"
							prop="phone"
							borderBottom
							labelWidth="100"
							clearable
							ref="item1">
							<u--input v-model="baseInfo.merchantShortName" border="none" placeholder="请输入商户简称"></u--input>
						</u-form-item>
						<u-form-item
							label="商户全称"
							prop="phone"
							borderBottom
							labelWidth="100"
							clearable
							ref="item1">
							<u--input v-model="baseInfo.merchantName" border="none" placeholder="请输入商户全称"></u--input>
						</u-form-item>
						<u-form-item
							label="行业"
							prop="phone"
							borderBottom
							labelWidth="100"
							clearable
							ref="item1">
							<view class=" w-flex" @click="showIndustryType(1)" style="flex: 1;justify-content: space-between;">
								<view class="w-flex">
									<view v-if="baseInfo.mccCode">{{baseInfo.mccCode}}</view>
									<view v-else class="w-font-12" style="color: #c0c4cc;">请选择行业</view>
								</view>
								<view><u-icon name="arrow-right" size="14" color="#d9d9d9"></u-icon></view>
							</view>
						</u-form-item>
						<u-form-item
							label="行业小类"
							prop="phone"
							borderBottom
							labelWidth="100"
							clearable
							v-if="baseInfo.mccCode"
							ref="item1">
							<view class=" w-flex" @click="showIndustryType(2)" style="flex: 1;justify-content: space-between;">
								<view class="w-flex">
									<view v-if="baseInfo.mccCode2">{{baseInfo.mccCode2}}</view>
									<view v-else class="w-font-12" style="color: #c0c4cc;">请选择行业</view>
								</view>
								<view><u-icon name="arrow-right" size="14" color="#d9d9d9"></u-icon></view>
							</view>
						</u-form-item>
						<u-form-item
							label="详细类别"
							prop="phone"
							borderBottom
							labelWidth="100"
							clearable
							v-if="baseInfo.mccCode2"
							ref="item1">
							<view class=" w-flex" @click="showIndustryType(3)" style="flex: 1;justify-content: space-between;">
								<view class="w-flex">
									<view v-if="baseInfo.mccCode3">{{baseInfo.mccName3}}</view>
									<view v-else class="w-font-12" style="color: #c0c4cc;">请选择行业</view>
								</view>
								<view><u-icon name="arrow-right" size="14" color="#d9d9d9"></u-icon></view>
							</view>
						</u-form-item>
					</u--form>
					<u-picker :show="IndustryType.show" @cancel="close"
						:closeOnClickOverlay="true" @confirm="confirmIndustryType"
						:columns="IndustryType.list" keyName="name">
					</u-picker>
				</view>
				
				<view class="gap"></view>
				<view class="w-p-10">
					<u--form
						labelPosition="left"
						:model="contactInfo"
						ref="form1" >
						<u-form-item
							label="联系人名字"
							prop="account"
							borderBottom
							labelWidth="100"
							clearable
							ref="item1">
							<u--input v-model="contactInfo.name" border="none" placeholder="建议联系人名字"></u--input>
						</u-form-item>

						<u-form-item
							label="联系人手机"
							prop="phone"
							borderBottom
							labelWidth="100"
							clearable
							ref="item1">
							<u--input v-model="contactInfo.mobile" border="none" type="number" placeholder="请输入手机号"></u--input>
						</u-form-item>
						
					</u--form>
				</view>
			
			</view>
			<view v-show="step === 2" class="stepTwo">
				<view class="ScanCodeRate">
					<view class="modifyRate w-flex w-flex-between w-p-10">
						<text>扫码费率</text>
						<text class="modify" @click="modify(0)">修改</text>
					</view>
					<view>
						<view class="w-flex" style="border-top: 1px solid rgb(223, 226, 229);border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);"></view>
							<view class="w-flex w-flex-center tableWidth" style="width: 74%;">
								T+1费率
							</view>
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>微信</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 74%;">
								{{WeChatRate}}%
							</view>
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>支付宝</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 74%;">
								{{AlipayRate}}%
							</view>
						</view>
					</view>
								
				</view>
				<view class="UnionPayRate">
					<view class="modifyRate w-flex w-flex-between w-p-10">
						<text>银联二维码费率</text>
						<text class="modify" @click="modify(1)">修改</text>
					</view>
					
					<view>
						<view class="w-flex" style="border-top: 1px solid rgb(223, 226, 229);border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);"></view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								<view class="w-center">
									<view>
										T+1费率
									</view>
									<view style="font-size: 12px;color: #999999;">
										(>1000元)
									</view>
								</view>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
								<view class="w-center">
									<view>
										T+1费率
									</view>
									<view style="font-size: 12px;color: #999999;">
										(<=1000元)
									</view>
								</view>
							</view>
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>信用卡</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								
								{{unionScan.t1Credit}}%
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
								{{unionScan2.t1Credit}}%
							</view>
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>借记卡</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								<view class="w-center">
									<view>
										{{unionScan.t1Debit}}%
									</view>
									<view style="font-size: 12px;color: #999999;">
										<!-- ({{unionScan.Capping || 0}}元封顶) -->
									</view>
								</view>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
								{{unionScan2.t1Debit}}%
							</view>
						</view>
					</view>
								
				</view>
				<view class="payCardRate">
					<view class="modifyRate w-flex w-flex-between w-p-10">
						<text>刷卡费率</text>
						<text class="modify" @click="modify(2)">修改</text>
					</view>
					
					<view>
						<view class="w-flex" style="border-top: 1px solid rgb(223, 226, 229);border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);"></view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								T+1费率
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
								T+0费率
							</view>
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);color: #999999;">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								卡类型
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								标准费率
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								标准费率
							</view>
							<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
								提现手续费
							</view> -->
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>信用卡</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								{{card.t1Credit}}%
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								{{card.t0Credit}}%
							</view>
							<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
								{{card.WithdrawalRate || 0}}元/笔
							</view> -->
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>借记卡</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								<view class="w-center">
									<view>
										{{card.t1Debit}}%
									</view>
									<view style="font-size: 12px;color: #999999;">
										<!-- ({{card.Capping || 0}}元封顶) -->
									</view>
								</view>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								{{card.t0Debit}}%
							</view>
							<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
								{{card.WithdrawalRate || 0}}元/笔
							</view> -->
						</view>
						<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
							<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
								<text>境外卡</text>
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								{{card.t1OverSee}}%
							</view>
							<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
								{{card.t0OverSee}}%
							</view>
							<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
								{{card.WithdrawalRate || 0}}元/笔
							</view> -->
						</view>
					</view>
				</view>
			</view>
			<view v-show="step === 1" class="stepThree">
				<view class="account w-flex">
					<view>
						<u-avatar src="../../static/icon/logo_gary.png" size="60" shape="circle"></u-avatar>
					</view>
					<view class="w-ml-15">
						<text>默认商户</text>
						<view class="w-flex w-mt-20">
							<text class="accountType" v-if="account.type === '1'">小微</text>
							<text class="accountType" v-if="account.type === '2'">个体</text>
							<text class="accountType" v-if="account.type === '3'">企业</text>
							<text class="accountType w-ml-10">{{baseInfo.merchantType}}</text>
						</view>
					</view>
				</view>
				<view class="w-flex w-p-10 w-mt-15 w-pb-15">
					<view class="w-w-50 w-flex">
						<u-avatar src="../../static/icon/icon_quota.png" size="30" shape="circle"></u-avatar>
						<navigator url="./shopedu"><text class="w-ml-15">商户额度</text></navigator>
						
					</view>
					<view class="w-w-50 w-flex">
						<u-avatar src="../../static/icon/icon_rate.png" size="30" shape="circle"></u-avatar>
						<text class="w-ml-15" @click="goSetRate">商户费率</text>
					</view>
				</view>
				<view class="styleReason" v-if="FailureReason !== ''">
					<view class="styleReasonContent">
						<text >审核失败原因：</text>
						<rich-text :nodes="FailureReason" ></rich-text>
					</view>
					
				</view>
				<view class="gap" v-else></view>
				<view class=" ">
					<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #f3f3f3;">
						<view class="w-flex">
							<text class="accWidth">乐刷商户号</text>
							<text>{{userInfo.merchant_id || '暂无'}}</text>
						</view>
						<view><text class="copy" @click="copy(userInfo.merchant_id)">复制</text></view>
					</view>
					<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
						<view class="w-flex">
							<text class="accWidth">登陆账号</text>
							<text>{{userName}}</text>
						</view>
						<view>
							<text class="copy" @click="copy(userName)">复制</text>
						</view>
					</view>
				</view>
				<view class="RequiredInfo">
					<text>必填资料</text>
				</view>
				<view class="RequiredInfoList w-flex w-flex-wrap">
					<view v-for="(item, index) in RequiredInfoList" :key="index" class="w-flex w-w-50 w-mt-20" @click="forDetail(item.path)" v-if="item.show">
						
						<u-avatar :src="item.iconPath" size="30" shape="circle" @click="forDetail(item.path)"></u-avatar>
						<view class="w-ml-10">
							<view>{{item.title}}</view>
							<view class="statusStyle" :style="item.statusName === '待录入'?'color: red;':'color: #1678ff;'" v-if="">{{item.statusName}}</view>
						</view>
					</view>
				</view>
				<!-- <view class="RequiredInfo">
					<text>选填资料</text>
				</view>
				<view class="RequiredInfoList w-flex w-flex-wrap OptionalInfoStyle">
					<view v-for="(item, index) in OptionalInfoList" :key="index" class="w-flex w-w-50 w-mt-20">
						<u-avatar :src="item.iconPath" size="30" shape="circle"></u-avatar>
						<view class="w-ml-10">
							<view>{{item.title}}</view>
							<view class="statusStyle">{{item.tip}}</view>
						</view>
					</view>
				</view> -->
			</view>
		
			<view class="m20" v-show="step === 0">
				<u-button type="primary" text="下一步" @click="nextChange(step)"></u-button>
			</view>
			<view class="m20 w-flex w-flex-between" v-show="step === 1" >
				<u-button type="primary" text="预览资料" @click="preview()" class="w-w-50 w-mr-15 previewBtn" :class="!examineStatus?'w-w-full w-mr-0':''"></u-button>
				<u-button type="primary" :text="btnText" v-if="examineStatus" :disabled="disabled" @click="submitExamine()" class="w-w-50 examineBtn"></u-button>
			</view>
			<view class="m20" v-show="step === 2">
				<u-button type="primary" text="保存费率" @click="setRate()"></u-button>
			</view>
		</view>
		
		<u-toast ref="uToast"></u-toast>
		<u-action-sheet :actions="ActionSheet.list" :show="ActionSheet.show"
		:closeOnClickOverlay="true"
		:showMessageCard="true"
		:cancel-btn="true"
		:mask-close-able="true"
		@close="close"
		cancelText="取消"
		@select="selectClick"></u-action-sheet>
		<u-modal :show="leshuaRegister.show" title="提示" :content='leshuaRegister.content' @confirm="hideLeshuaRegister"></u-modal>
	</view>
</template>

<script>
export default {
	data() {
		return {
			formData: {
				account: '',
				password: '',
				phone: ''
			},
			inputType: 'text',
			current: 0,
			baseInfo: {
				merchantType: '总店',
				merchantShortName: '',
				merchantName: '',
				mccCode: '',
				mccCode2: '',
				mccCode3: '',
				mccName3: ''
			},
			ActionSheet: {
				list: [
					{
						name:'总店',
						color:'#000'
					},
					{
						name:'分店',
						color:'#000'
					},
				],
				show: false,
			},
			IndustryType: {
				show: false,
				list: [
					['中国', '美国'],
					['深圳', '厦门', '上海', '拉萨']
				]
			},
			columnData: [
				['深圳', '厦门', '上海', '拉萨'],
				['得州', '华盛顿', '纽约', '阿拉斯加'],
			],
			step: 0,
			account: {
				type: '',
				id: '',
				status: ''
			},
			RequiredInfoList: [
				{
					iconPath: '../../static/icon/icon_MerInfo.png',
					title: '商户信息',
					statusName: '待录入',
					path: './uploadMerchantInfo',
					show: true
				},
				{
					iconPath: '../../static/icon/icon_settleInfo.png',
					title: '结算信息',
					statusName: '待录入',
					path: './uploadSettleAccountsInfo',
					show: true
				},
				{
					iconPath: '../../static/icon/icon_managInfo.png',
					title: '经营信息',
					statusName: '待录入',
					path: './uploadShopInfo',
					show: true
				},
				{
					iconPath: '../../static/icon/icon_legalInfo.png',
					title: '法人信息',
					statusName: '待录入',
					path: './uploadlegalPersonInfo',
					show: true
				}
			],
			OptionalInfoList: [
				{
					iconPath: '../../static/icon/shop2.jpg',
					title: '公众号支付',
					tip: '支付参数配置'
				},
				{
					iconPath: '../../static/icon/shop2.jpg',
					title: '图片上传',
					tip: '上传其他材料证明'
				}
			],
			WeChatRate: 0,
			AlipayRate: 0,
			unionScan: {
				t1Credit: 0,
				t1Debit: 0,
				t0Credit: 0,
				t0Debit: 0,
				Capping:0
			},
			unionScan2: {
				t1Credit: 0,
				t1Debit: 0,
				t0Credit: 0,
				t0Debit: 0
			},
			card: {
				t1Credit: 0,
				t0Credit: 0,
				t1Debit: 0,
				t0Debit: 0,
				t1OverSee: 0,
				t0OverSee: 0,
				WithdrawalRate: 0
			},
			parameterType: null,
			shopInfo: {}, // 门店信息
			addressInfo: {}, // 店铺信息
			accountInfo: {}, // 结算信息
			licenseInfo: {}, // 营业资质信息
			legalPerson: {}, // 法人信息
			contactInfo: {},
			leshuaRegister: {
				show: false,
				content: ''
			},
			userInfo: {},
			examineStatus: true,
			phoneStatus: false,
			asyncCheckMcc: false,
			dataUserID: null,
			disabled: false,
			btnText: '提交审核',
			FailureReason: '',
			successRate: false,
			userName: ''
		}
	},
	onShow() {
		this.getStorageInfo()
	},
	onLoad(e) {
		this.removeData()
		if (e.name) {
			this.userName = e.name
		}
		if (e.type) {
			this.account.type = e.type
		}
		if (e.id) {
			this.account.id = e.id
			this.dataUserID = e.id
			uni.setStorageSync("dataUserID", this.dataUserID)
			this.account.status = e.status
			if (e.status) {
				this.step = 1
				this.current = this.step;
			}
			
			if (this.account.status === '3' || this.account.status === '5') {
				this.examineStatus = true
				
			} else {
				this.examineStatus = false
			}
			if (this.account.status === '5') {
				this.btnText = '商户入驻资料修改'
			}
			this.current = this.step
			this.getOldData()
		}
		
		if (e.type === '1') {
			for (let item of this.RequiredInfoList) {
				if (item.path === './uploadShopInfo') {
					item.show = false
				}
			}
		}
		this.userInfo = uni.getStorageSync("YNF_INFO")
		this.getRate()
	},
	methods: {
		// 返回页面
		onClickBack () {
			if(this.account.status) {
				uni.navigateBack()
				return
			}
			if (this.step > 0) {
				this.step = this.step-1;
				this.current = this.step;
			} else {
				uni.navigateBack()
			}
			
		},
		removeData () {
			uni.removeStorageSync("contactInfo")
			uni.removeStorageSync("payCard")
			uni.removeStorageSync("legalPerson")
			uni.removeStorageSync("licenseInfo")
			uni.removeStorageSync("accountInfo")
			uni.removeStorageSync("baseInfo")
			uni.removeStorageSync("addressInfo")
			uni.removeStorageSync("UnionPayRate")
			uni.removeStorageSync("ScanCodeRate")
			uni.removeStorageSync("shopInfo")
			this.baseInfo.merchantShortName = ''
			this.baseInfo.merchantName = ''
			this.baseInfo.mccCode = ''
			this.baseInfo.mccCode2 = ''
			this.baseInfo.mccCode3 = ''
			this.baseInfo.mccName3 = ''
			this.shopInfo = {}
			this.addressInfo = {}
			this.accountInfo = {}
			this.licenseInfo = {}
			this.legalPerson = {}
			this.contactInfo = {}
		},
		async saveStepData () {
			let params = {
				'row[baseInfo][merchantType]': Number(this.account.type),
				'row[baseInfo][merchantShortName]': this.baseInfo.merchantShortName,
				'row[baseInfo][merchantName]': this.baseInfo.merchantName,
				'row[baseInfo][mccCode]': this.baseInfo.mccCode3,
				'row[contactInfo][name]': this.contactInfo.name,
				'row[contactInfo][mobile]': this.contactInfo.mobile,
			}
			
			const res = await this.$API({url: '/api/user/leshua_register1', method:"POST", data: params,})
			if (res.code === 1) {
				this.dataUserID = res.data.user_id
				uni.setStorageSync("dataUserID", this.dataUserID)
			}
		},
		getStorageInfo () {
			if (uni.getStorageSync("baseInfo")) {
				this.baseInfo.merchantShortName = uni.getStorageSync("baseInfo").merchantShortName
				this.baseInfo.merchantName = uni.getStorageSync("baseInfo").merchantName
				this.account.type = uni.getStorageSync("baseInfo").merchantType
				if (uni.getStorageSync("baseInfo").merchantType === '1') {
					this.RequiredInfoList[2].show = false
				}
				this.getMccInfo(uni.getStorageSync("baseInfo").mccCode)
			}
			if (uni.getStorageSync("ScanCodeRate")) {
				this.WeChatRate = uni.getStorageSync("ScanCodeRate").WeChatRate
				this.AlipayRate = uni.getStorageSync("ScanCodeRate").AlipayRate
			}
			if (uni.getStorageSync("UnionPayRate")) {
				this.unionScan.t1Credit = uni.getStorageSync("UnionPayRate").t1Credit;
				this.unionScan.t1Debit = uni.getStorageSync("UnionPayRate").t1Debit;
				this.unionScan2.t1Credit = uni.getStorageSync("UnionPayRate").t1Credit_Scan2;
				this.unionScan2.t1Debit = uni.getStorageSync("UnionPayRate").t1Debit_Scan2;
			}
			if (uni.getStorageSync("payCard")) {
				this.card = uni.getStorageSync("payCard");
			}
			if (uni.getStorageSync("addressInfo")) {
				this.addressInfo = uni.getStorageSync("addressInfo")
				this.shopInfo = uni.getStorageSync("shopInfo")
				this.RequiredInfoList[0].statusName = '已录入'
			}
			if (uni.getStorageSync("accountInfo")) {
				this.accountInfo = uni.getStorageSync("accountInfo")
				this.RequiredInfoList[1].statusName = '已录入'
			}
			if (uni.getStorageSync("licenseInfo")) {
				this.licenseInfo = uni.getStorageSync("licenseInfo")
				this.RequiredInfoList[2].statusName = '已录入'
			}
			if (uni.getStorageSync("legalPerson")) {
				this.legalPerson = uni.getStorageSync("legalPerson")
				this.RequiredInfoList[3].statusName = '已录入'
			}
			if (uni.getStorageSync("contactInfo")) {
				this.contactInfo = uni.getStorageSync("contactInfo")
			}
			if (uni.getStorageSync("dataUserID")) {
				this.dataUserID = uni.getStorageSync("dataUserID")
			}
			
		},
		async getOldData () {
			let params = {
				user_id: Number(this.account.id)
			}
			const res = await this.$API({url: '/api/user/get_les_merchant', method:"GET", data: params,})
			if (res.code === 1) {
				if (res.data.error_msg) {
					let strReason = (res.data.error_msg).lastIndexOf("\-")
					this.FailureReason = res.data.error_msg.substring(strReason+1,res.data.error_msg.length)
				}
				this.getMccInfo(res.data.baseInfo.mccCode)
				let addressInfo = {
					address: res.data.addressInfo.address,
					areaCode: res.data.addressInfo.areaCode,
					cityCode: res.data.addressInfo.cityCode,
					provinceCode: res.data.addressInfo.provinceCode,
				}
				let accountInfo = {
					bankCardFrontPic: 'https://ynf.xxhf.cn/uploads/'+res.data.accountInfo.bankCardFrontPic,
					bankCardNo: res.data.accountInfo.bankCardNo,
					holder: res.data.accountInfo.holder,
					idCardNo: res.data.accountInfo.idCardNo,
					legalFlag: Number(res.data.accountInfo.legalFlag),
					nonLegIdcardBackPic: res.data.accountInfo.nonLegIdcardBackPic !==""?'https://ynf.xxhf.cn/uploads/'+res.data.accountInfo.nonLegIdcardBackPic:'',
					nonLegIdcardFrontPic: res.data.accountInfo.nonLegIdcardFrontPic !==""?'https://ynf.xxhf.cn/uploads/'+res.data.accountInfo.nonLegIdcardFrontPic:'',
					nonLegSettleAuthPic: res.data.accountInfo.nonLegSettleAuthPic !==""?'https://ynf.xxhf.cn/uploads/'+res.data.accountInfo.nonLegSettleAuthPic:'',
					type: res.data.accountInfo.type,
					unionpay: res.data.accountInfo.unionpay,
				}
				let baseInfo = {
					mccCode: res.data.baseInfo.mccCode,
					merchantName: res.data.baseInfo.merchantName,
					merchantShortName: res.data.baseInfo.merchantShortName,
					merchantType: res.data.baseInfo.merchantType,
				}
				let contactInfo = {
					mobile: res.data.contactInfo.mobile,
					name: res.data.contactInfo.name,
				}
				let legalPerson = {
					idCardEnd: res.data.legalPerson.idCardEnd,
					idCardNo: res.data.legalPerson.idCardNo,
					idCardStart: res.data.legalPerson.idCardStart,
					idcardBackPic: 'https://ynf.xxhf.cn/uploads/'+res.data.legalPerson.idcardBackPic,
					idcardFrontPic: 'https://ynf.xxhf.cn/uploads/'+res.data.legalPerson.idcardFrontPic,
					legalName: res.data.legalPerson.legalName,
				}
				let licenseInfo = {
					license: res.data.licenseInfo.license,
					licenseAddress: res.data.licenseInfo.licenseAddress,
					licenseEnd: res.data.licenseInfo.licenseEnd,
					licenseFullName: res.data.licenseInfo.licenseFullName,
					licensePic: 'https://ynf.xxhf.cn/uploads/'+res.data.licenseInfo.licensePic,
					licenseStart: res.data.licenseInfo.licenseStart,
				}
				let shopInfo = {
					cashierDeskPic: 'https://ynf.xxhf.cn/uploads/'+res.data.shopInfo.cashierDeskPic,
					doorPic: 'https://ynf.xxhf.cn/uploads/'+res.data.shopInfo.doorPic,
					insidePic: 'https://ynf.xxhf.cn/uploads/'+res.data.shopInfo.insidePic,
				}
				if (res.data.addressInfo.address) {
					uni.setStorageSync("addressInfo", addressInfo)
				}
				if (res.data.accountInfo.bankCardNo) {
					uni.setStorageSync("accountInfo", accountInfo)
				}
				if (res.data.legalPerson.legalName) {
					uni.setStorageSync("legalPerson", legalPerson)
				}
				if(res.data.licenseInfo.license) {
					uni.setStorageSync("licenseInfo", licenseInfo)
				}
				if (res.data.shopInfo.cashierDeskPic) {
					uni.setStorageSync("shopInfo", shopInfo)
				}
				
				uni.setStorageSync("baseInfo", baseInfo)
				uni.setStorageSync("contactInfo", contactInfo)
				
				
				
				this.getStorageInfo()
			}
		},
		async getMccInfo (mccCode) {

			let params = {
				  'param[mccCode]': mccCode,
			}
			const res = await this.$API({url: '/api/user/mcc', method:"GET", data: params,})
			if (this.asyncCheckMcc) {
				return
			}
			this.baseInfo.mccCode = res.data.data[0].grandpaText
			this.baseInfo.mccCode2 = res.data.data[0].fatherText
			this.baseInfo.mccCode3 = res.data.data[0].mccCode
			this.baseInfo.mccName3 = res.data.data[0].mccText
			
		},

		copy(value) {
		  uni.setClipboardData({
		      data: value,
		     success: function () {
		     //调用方法成功
		        console.log('success');
		    }
		  })
		 },
		
		seePwd () {
			this.inputType === 'password'?this.inputType = 'text':this.inputType = 'password';
		},
		async nextChange (step) {
			
			if (this.baseInfo.merchantShortName === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入商户简称",
				})
				return
			}
			if (this.baseInfo.merchantName === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入商户全称",
				})
				return
			}
			if (this.baseInfo.mccCode === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请选择行业",
				})
				return
			}
			if (this.baseInfo.mccCode2 === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请选择行业小类",
				})
				return
			}
			if (this.baseInfo.mccCode3=== '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请选择行业详细类别",
				})
				return
			}
			if (this.contactInfo.name=== '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入联系人姓名",
				})
				return
			}
			if (this.contactInfo.mobile=== '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入联系人手机号",
				})
				return
			}
			
			let params = {
				phone: this.contactInfo.mobile
			}
			const res = await this.$API({url: '/api/user/is_use_phone', method:"GET", data: params,})
			if (res.code === 1) {
				this.phoneStatus = true
			} else {
				this.phoneStatus = false
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: res.msg,
				})
			}
			if (!this.phoneStatus) {
				return
			}
			this.userName = this.baseInfo.merchantName
			this.saveStepData()
			this.step = step+1;
			this.current = this.step
			if(this.step === 1) {
				this.getRate()
				
				let baseInfo = {
					mccCode: this.baseInfo.mccCode3,
					merchantName: this.baseInfo.merchantName,
					merchantShortName: this.baseInfo.merchantShortName,
					merchantType: this.account.type,
				}
				let contactInfo = {
					mobile: this.contactInfo.mobile,
					name: this.contactInfo.name,
				}
				uni.setStorageSync("baseInfo", baseInfo)
				uni.setStorageSync("contactInfo", contactInfo)
			}
			if (this.step === 2) {
				this.setRate()
			}
		},
		showShopType () {
			this.ActionSheet.show = true
		},
		showIndustryType (type) {
			this.parameterType = type
			this.IndustryType.show = true
			this.getMccCode()
		},
		selectClick (index) {
			this.baseInfo.merchantType = index.name
		},
		close () {
			this.ActionSheet.show = false
			this.IndustryType.show = false
		},
		forDetail (path) {
			uni.navigateTo({
				url: path+'?id='+this.account.id
			})
		},
		modify (type) {
			uni.navigateTo({
				url: './modifyRate?modifyType='+type
			})
		},
		preview () {
			uni.navigateTo({
				url: './preview?id='+this.account.id
			})
		},
		async submitExamine () {
			if (!uni.getStorageSync("shopInfo")) {
				this.leshuaRegister.show = true
				this.leshuaRegister.content = '商户信息不能为空'
				return
			}
			if (!uni.getStorageSync("accountInfo")) {
				this.leshuaRegister.show = true
				this.leshuaRegister.content = '结算信息不能为空'
				return
			}
			if(Number(this.account.type) !== 1) {
				if (!uni.getStorageSync("licenseInfo")) {
					this.leshuaRegister.show = true
					this.leshuaRegister.content = '经营信息不能为空'
					return
				}
			}
			if (!uni.getStorageSync("legalPerson")) {
				this.leshuaRegister.show = true
				this.leshuaRegister.content = '法人信息不能为空'
				return
			}
			this.legalPerson.idcardBackPic = this.legalPerson.idcardBackPic.substr(28,this.legalPerson.idcardBackPic.length)
			this.legalPerson.idcardFrontPic = this.legalPerson.idcardFrontPic.substr(28,this.legalPerson.idcardFrontPic.length)
			this.accountInfo.bankCardFrontPic = this.accountInfo.bankCardFrontPic.substr(28,this.accountInfo.bankCardFrontPic.length)
			
			this.shopInfo.cashierDeskPic = this.shopInfo.cashierDeskPic.substr(28,this.shopInfo.cashierDeskPic.length)
			this.shopInfo.doorPic = this.shopInfo.doorPic.substr(28,this.shopInfo.doorPic.length)
			this.shopInfo.insidePic = this.shopInfo.insidePic.substr(28,this.shopInfo.insidePic.length)
			
			if (Number(this.account.type) === 1) {
				this.licenseInfo.license = ''
				this.licenseInfo.licenseAddress = ''
				this.licenseInfo.licenseEnd = ''
				this.licenseInfo.licenseFullName = ''
				this.licenseInfo.licensePic = ''
				this.licenseInfo.licenseStart = ''
			} else {
				this.licenseInfo.licensePic = this.licenseInfo.licensePic.substr(28,this.licenseInfo.licensePic.length)
			}
			if (Number(this.accountInfo.legalFlag) === 1) {
				this.accountInfo.nonLegIdcardBackPic = ''
				this.accountInfo.nonLegIdcardFrontPic = ''
				this.accountInfo.nonLegSettleAuthPic = ''
			} else {
				this.accountInfo.nonLegIdcardBackPic = this.accountInfo.nonLegIdcardBackPic.substr(28,this.accountInfo.nonLegIdcardBackPic.length)
				this.accountInfo.nonLegIdcardFrontPic = this.accountInfo.nonLegIdcardFrontPic.substr(28,this.accountInfo.nonLegIdcardFrontPic.length)
				this.accountInfo.nonLegSettleAuthPic = this.accountInfo.nonLegSettleAuthPic.substr(28,this.accountInfo.nonLegSettleAuthPic.length)
			}
			
			let params = {
				provinceName: this.addressInfo.provinceName,
				cityName: this.addressInfo.cityName,
				areaName: this.addressInfo.areaName,
				user_id: this.dataUserID,
				row: 
					{
						baseInfo: { // 商户基本信息
							merchantType: Number(this.account.type), // 商户类型1: 个人 2: 个体 3: 企业
							merchantShortName: this.baseInfo.merchantShortName, // 商户简称
							merchantName: this.baseInfo.merchantName, // 商户全称
							mccCode: this.baseInfo.mccCode3, // MccCode接口获取
						},
						legalPerson: this.legalPerson,
						contactInfo: this.contactInfo,
						addressInfo: this.addressInfo,
						licenseInfo: this.licenseInfo,
						accountInfo: this.accountInfo,
						shopInfo: this.shopInfo
					}
			}
			
			let params1 = this.$qs.stringify(params)
			let res = null
			if (Number(this.account.status) === 5) {
				res = await this.$API({url: '/api/user/leshua_update', method:"POST", data: params1,})
			} else {
				res = await this.$API({url: '/api/user/leshua_register', method:"POST", data: params1,})
			}
			
			if (res.code === 1) {

				uni.showToast({
					title: res.msg,
					duration: 2000,
					mask: true,
					success: (res)=> {
						this.step=2
						this.current = this.step
					}
				});
				this.examineStatus = false
			} else {
				this.leshuaRegister.show = true
				this.leshuaRegister.content = res.msg
			}
		},
		hideLeshuaRegister () {
			this.leshuaRegister.show = false
			this.leshuaRegister.content = ''
		},
		async getMccCode () {
			
			this.IndustryType.list = [
				[]
			]
			if(this.parameterType === 1) {
				let params = {}
				const res = await this.$API({url: '/api/user/les_MccCode1', method:"GET", data: params})
				if (res.code === 1) {
					
					for (let item of res.data) {
						this.IndustryType.list[0].push(item.name)
					}
				}
			}
			if(this.parameterType === 2) {
				let params = {
					name: this.baseInfo.mccCode
				}
				const res = await this.$API({url: '/api/user/les_MccCode2', method:"GET", data: params})
				if (res.code === 1) {
					for (let item of res.data) {
						this.IndustryType.list[0].push(item.name)
					}
				}
			}
			if(this.parameterType === 3) {
				let params = {
					name: this.baseInfo.mccCode2
				}
				const res = await this.$API({url: '/api/user/les_MccCode3', method:"GET", data: params})
				if (res.code === 1) {
					for (let item of res.data) {
						this.IndustryType.list[0].push(item)
					}
				}
			}
		},

		confirmIndustryType (e) {
			if(this.parameterType === 1) {
				this.baseInfo.mccCode = e.value[0]
			}
			if(this.parameterType === 2) {
				if (e.value[0]) {
					this.baseInfo.mccCode2 = e.value[0]
				} else {
					this.baseInfo.mccCode2 = e.values[0][0]
				}
			}
			if(this.parameterType === 3) {
				this.baseInfo.mccName3 = e.value[0].name
				this.baseInfo.mccCode3 = e.value[0].value
			}
			this.IndustryType.show = false
		},
		async getRate () {
			let params = {
				user_id: this.dataUserID,
			}
			const res = await this.$API({url: '/api/user/user_rate', method:"GET", data: params})
			if (res.code === 1) {
				this.WeChatRate = res.data.weixin
				this.AlipayRate = res.data.alipay
				this.unionScan = res.data.unionScan
				this.unionScan2 = res.data.unionScan2
				this.card = res.data.card
				this.successRate = true
				let ScanCodeRate = {
					WeChatRate: res.data.weixin,
					AlipayRate: res.data.alipay,
				}
				let UnionPayRate = {
					t1Debit: res.data.unionScan.t1Debit,
					t1Credit: res.data.unionScan.t1Credit,
					t1Debit_Scan2: res.data.unionScan2.t1Debit,
					t1Credit_Scan2: res.data.unionScan2.t1Credit,
				}
				uni.setStorageSync("payCard",res.data.card)
				uni.setStorageSync("UnionPayRate", UnionPayRate)
				uni.setStorageSync("ScanCodeRate", ScanCodeRate)
			}
		},
		async setRate () {
			
			let params = {
				user_id: this.dataUserID,
				param: {
					weixin: this.WeChatRate,
					alipay: this.AlipayRate,
					unionScan: {
						t1Credit: this.unionScan.t1Credit,
						t1Debit: this.unionScan.t1Debit,
						t0Credit: 0,
						t0Debit: 0,
					},
					unionScan2: {
						t1Credit: this.unionScan2.t1Credit,
						t1Debit: this.unionScan2.t1Debit,
						t0Credit: 0,
						t0Debit: 0,
					},
					card: this.card,
				}
				
			}
			let params1 = this.$qs.stringify(params)
			const res = await this.$API({url: '/api/user/save_user_rate', method:"POST", data: params1})

			if (res.code === 1) {
				uni.showToast({
					title: res.msg,
					duration: 2000,
					mask: true,
					success: (res)=> {
						setTimeout(()=>{
							uni.switchTab({
								url:'/pages/index/index'
							});
						},1000)
					}
				});
			}
		},
		goSetRate () {
			if (!this.successRate) {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: '尚未完成进件,无法查看费率',
				})
				return
			}
			uni.navigateTo({
				url: './shoprate'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.content {
	background: #FFFFFF;
	padding-top: 30rpx;
	    overflow: auto;
	.slot-icon {
		display: flex;
		align-items: center;
		justify-content: center;
		background: #d9d9d9;
		color: #FFFFFF;
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;
	}
	.text-active {
		/deep/.u-text__value{
			color: #1678ff;
		}
	}
	.slot-icon-active {
		background: #1678ff;
	}
	.newMerchant {
		color: #999999;
		padding: 20rpx;
		background: #f1f1f1;
	}
	.shopType {
		width: 100%;
		padding: 0 20rpx;
		justify-content: space-between;
	}
	.stepTwo {
		.modifyRate {
			background: #F1F1F1;
			padding: 20rpx;
			color: #999999;
			.modify {
				border-radius: 26rpx;
				color: #1678ff;
				border: 1px solid #1678ff;
				padding: 4rpx 20rpx;
			}
		}
	}
	.styleReason {
		background: #F1F1F1;
		
		padding: 20rpx;
		.styleReasonContent {
			border: 1px solid red;
			padding: 20rpx;
			border-radius: 20rpx;
			color: red;
		}
	}
	.tableWidth{
		height: 90rpx;
	}
	.stepThree {
		.account {
			margin: 20rpx;
			height: 250rpx;
			background: #1678ff;
			color: #FFFFFF;
			border-radius: 15rpx;
			padding: 0 30rpx;
			.accountType {
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 12rpx;
				border: 1px solid #FFFFFF;
				border-bottom-left-radius: 4px;
				border-top-right-radius: 4px;
				font-size: 12px;
			}
		}
		.accWidth {
			display: flex;
			width: 170rpx;
			min-width: 170rpx;
		}
		
		.RequiredInfo {
			font-size: 16px;
			font-weight: 600;
			padding: 20rpx;
			background: #F1F1F1;
		}
		.RequiredInfoList {
			padding: 40rpx;
			padding-top: 0;
			.statusStyle {
				font-size: 12px;
				color: red;
			}
		}
		.OptionalInfoStyle {
			.statusStyle {
				color: #999999;
			}
		}
	}
}
.previewBtn {
	background-color: transparent;
	border-color: #1678ff;
	color: #1678ff;
	border-radius: 12rpx;
}
.examineBtn {
	background-color: #1678ff;
	border-color: #1678ff;
	color: #FFFFFF;
	border-radius: 12rpx;
}
/deep/.u-picker__view__column__item {
	line-height: initial !important;
}
</style>
